package com.bw.my.mvvm.user.viewmodel;

import android.text.TextUtils;

import androidx.databinding.ObservableField;

import com.bw.mvvm.entity.BaseEntity;
import com.bw.mvvm.fleld.UIField;
import com.bw.mvvm.mvvm.viewmodel.BaseViewModel;
import com.bw.my.mvvm.user.model.UserUpdateModel;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class UserUpDateViewModel extends BaseViewModel<UserUpdateModel> {
    public ObservableField<String> phone=new ObservableField<>();
    public ObservableField<String> lock=new ObservableField<>();
    HashMap<String,Object> map;

    protected void result(BaseEntity baseEntity) {
        if (baseEntity.getStatus()==-1){
            showMsg(baseEntity.getMessage());
            return;
        }
        if ("密码修改成功".equals(baseEntity.getMessage())){
            showMsg(baseEntity.getMessage());
            finishPage();
            return;
        }
        showMsg(baseEntity.getMessage());
        if (map==null) {
            map = new HashMap<>();
        }
        map.clear();
    }

    public void UpdataClick(){
        resetNext();
    }

    public void back(){
        finishPage();
    }

    public void resetNext(){
        if (TextUtils.isEmpty(phone.get().trim())||TextUtils.isEmpty(lock.get().trim())){
            showMsg("内容不可为空");
            return;
        }
        if (map==null) {
            map = new HashMap<>();
        }
        map.clear();
        map.put("mobile",phone.get().trim());
        map.put("verifyCode",lock.get().trim());
        m.requestUpdate(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }

    public void upDataPwd(){
        if (TextUtils.isEmpty(phone.get().trim())||TextUtils.isEmpty(lock.get().trim())){
            showMsg("内容不可为空");
            return;
        }
        if (map==null) {
            map = new HashMap<>();
        }
        map.clear();

        map.put("mobile",phone.get().trim());
        map.put("pwd",lock.get().trim());
        m.requestSet(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }
}
